/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>店铺拼团活动管理</h3>
        <h5>拼团活动管理, 由总平台设置管理</h5>
      </div>
    </div>

    <div
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>抢购管理, 由平台设置管理.</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>

    <div class="mDiv">
      <div class="ftitle">
        <h3>店铺拼团活动列表</h3>
        <h5>(共 {{page.total}} 条记录)</h5>
      </div>
      <div class="fbutton">
        <a href="http://help.tp-shop.cn/Index/Help/info/cat_id/5/id/47.html" target="_blank">
          <div class="add" title="帮助">
            <span>帮助</span>
          </div>
        </a>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-input
          class="searchinput"
          v-model="query.act_name"
          width="10"
          size="small"
          placeholder="拼团标题"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox">
      <el-table :data="page.records" style="width: 100%">
        <el-table-column label="拼团标题" prop="act_name" width="300" show-overflow-tooltip></el-table-column>
        <el-table-column label="拼团商品" prop="goods_name" width="300" show-overflow-tooltip></el-table-column>
        <el-table-column label="拼团类型" :formatter="teamTypeFormat" width="90"></el-table-column>
        <el-table-column label="成团有效期" :formatter="timeLimitFormat" width="90"></el-table-column>
        <el-table-column label="成团人数" prop="needer" width="90"></el-table-column>
        <el-table-column label="购买限制数" prop="buy_limit" width="90"></el-table-column>
        <el-table-column label="已成团个数" prop="success_count" width="90"></el-table-column>
        <el-table-column label="所属店铺" prop="store.store_name" width="200"></el-table-column>
        <el-table-column label="状态" :formatter="statusFormat" width="90"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <router-link :to="{path:'/index/marketing/team_activity/'+scope.row.team_id}">
                <el-button size="small" icon="el-icon-document">详情</el-button>
              </router-link>
              <span style="margin-right: 15px;" v-if="scope.row.status == 0">
                <el-button size="small" @click="changeStatus(scope.row, 1)" icon="el-icon-check">通过</el-button>
                <el-button size="small" @click="changeStatus(scope.row, 2)" icon="el-icon-close">拒绝</el-button>
              </span>
              <el-button
                size="small"
                @click="close(scope.row)"
                icon="el-icon-remove"
                v-if="scope.row.status == 1 && scope.row.is_lottery == 0"
              >取消</el-button>
              <router-link :to="{path:'/index/order/team/'+scope.row.team_id}">
                <el-button size="small" icon="el-icon-s-order">订单数据</el-button>
              </router-link>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getShareTeamPage, updateShareTeam } from "@/utils/api";
export default {
  data() {
    return {
      query: {
        team_type: this.$route.params.team_type,
        act_name: null
      },
      page: {
        total: 0
      },
      currentPage: this.$route.params.currentPage || 1,
      pageSize: 10
    };
  },
  components: {},
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      that.query.page = that.currentPage;
      that.query.size = that.pageSize;
	  that.query.status = that.$route.params.status;
      getShareTeamPage(that.query).then(function(res) {
        that.page = res;
      });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    },
    changeStatus(row, status) {
      var that = this;
      var prompt = status == 1 ? "通过？" : "拒绝？";
      var data = {
        team_id: row.team_id,
        status: status
      };
      this.$confirm("确认" + prompt, "提示", {
        confirmButtonText: "是",
        cancelButtonText: "否",
        type: "warning"
      })
        .then(() => {
          updateShareTeam(data).then(function(res) {
            if (res.status == 1) {
              that.$message({
                type: "success",
                message: "操作成功!",
                onClose: function() {
                  that.getPage();
                }
              });
            } else {
              that.$message.error("操作失败,失败原因:" + res.msg);
            }
          });
        })
        .catch(() => {});
    },
    close(row) {
      var that = this;
      var data = {
        team_id: row.team_id,
        status: 3
      };
      this.$confirm("是否取消该活动?", "提示", {
        confirmButtonText: "是",
        cancelButtonText: "否",
        type: "warning"
      })
        .then(() => {
          updateShareTeam(data).then(function(res) {
            if (res.status == 1) {
              that.$message({
                type: "success",
                message: "取消成功!"
              });
              that.getPage();
            }
          });
        })
        .catch(() => {});
    },
    teamTypeFormat(row, column) {
      if (row.team_type == 0) {
        return "分享团";
      }
      if (row.team_type == 1) {
        return "佣金团";
      }
      if (row.team_type == 2) {
        return "抽奖团";
      }
      return "无类型";
    },
    timeLimitFormat(row, column) {
      return row.time_limit / (60 * 60) + "小时";
    },
    statusFormat(row, column) {
      if (row.is_lottery == 1) {
        return "已开奖";
      }
      if (row.status == 0) {
        return "审核中";
      }
      if (row.status == 1) {
        return "进行中";
      }
      if (row.status == 2) {
        return "审核失败";
      }
      if (row.status == 2) {
        return "管理员关闭";
      }
      return "无状态";
    }
  },
  watch: {
    $route: function(to, from) {
      //执行数据更新查询
      this.query.team_type = to.params.team_type;
      this.query.act_name = null;
      this.getPage();
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
</style>
